package service;

import domain.*;
import static service.Data.*;

public class NameListService {
    private Employee[]employees;
    public NameListService(){
        employees=new Employee[EMPLOYEES.length];
        for(int i=0;i<employees.length;i++)
        {
            int type=Integer.parseInt(EMPLOYEES[i][0]);
            int id=Integer.parseInt(EMPLOYEES[i][1]);
            String name=EMPLOYEES[i][2];
            int age=Integer.parseInt(EMPLOYEES[i][3]);
            int salary=Integer.parseInt(EMPLOYEES[i][4]);
            double bounus;
            Equipment equipment;
            switch (type)
            {
                case EMPLOYEE:
                    employees[i]=new Employee(id, name, age, salary);
                break;
                case PROGRAMMER:
                     equipment=creatEquipment(i);
                    employees[i]=new Programmer(id,name,age,salary,equipment);
                    break;
                case DESIGNER:
                    equipment=creatEquipment(i);
                    bounus=Double.parseDouble(EMPLOYEES[i][5]);
                    employees[i]=new Designer(id,name,age,salary,equipment,bounus);
                    break;
                case ARCHITECT:
                    equipment=creatEquipment(i);
                    bounus=Double.parseDouble(EMPLOYEES[i][5]);
                    int stock=Integer.parseInt(EMPLOYEES[i][6]);
                    employees[i]=new Architect(id,name,age,salary,equipment,bounus,stock);
                    break;

            }
        }
    }
    private Equipment creatEquipment(int i)
    {
        int key=Integer.parseInt(EQUIPMENTS[i][0]);
        String model=EQUIPMENTS[i][1];
    switch(key)
    {
        case PC://21
            String display=EQUIPMENTS[i][2];
        return new PC(model,display);
        case NOTEBOOK://22
            double price=Double.parseDouble(EQUIPMENTS[i][2]);
            return new NoteBook(model,price);
        case PRINTER://23
                    String type=EQUIPMENTS[i][2];
            return new Printer(model,type);

    }
return null;
    }
    public  Employee[]getAllEmployees()
    {
return employees;
    }
    public Employee getEmployee(int id)throws TeamException
    {for(Employee e:employees)
        {
            if(e.getId()==id)
            return e;
        }

            throw new TeamException("找不到指定的员工！");
        }
    }


